#ifndef _NE_DYNAMIC_GEOMETRY_H_
#define _NE_DYNAMIC_GEOMETRY_H_

#include <mathematics/Color.h>
#include <mathematics/Vector3.h>
#include <graphics/GLBufferObjectManager.h>
#include <graphics/VertexData.h>
#include <graphics/IndexData.h>

namespace ne
{
    class NEAPI DynamicGeometry
    {
        public:
            explicit DynamicGeometry(const PrimitiveType pt);

            PrimitiveType getPrimitiveType() const;

            void addPosition(const Vector3 &v);

            void addNormal(const Vector3 &n);

            void addTangent(const Vector3 &t);

            void addColor(const Color &c);

            void addTexCoord(const Vector2 &t);

            void addIndex(const uint32_t index);

            uint32_t getVertexCount() const;

            void beginGeometry();
            void endGeometry();
            void clearGeometry();

            void beginIndex();
            void endIndex();
            void clearIndex();

            GLBufferObjectPtr getVertexBuffer() const;

            GLBufferObjectPtr getIndexBuffer() const;

            VertexDataPtr getVertexData() const;

            IndexDataPtr getIndexData() const;

            ~DynamicGeometry();

        private:
            void _createBuffer();
            void _writeBuffer();
            void _destroyBuffer();

            void _createIndexBuffer();
            void _writeIndexBuffer();
            void _destroyIndexBuffer();

            DynamicGeometry(const DynamicGeometry &);

            DynamicGeometry& operator = (const DynamicGeometry &);

        private:
            PrimitiveType mPrimitiveType;
            GLBufferObjectPtr mpVertexBuffer;
            GLBufferObjectPtr mpIndexBuffer;
            VertexDataPtr mpVertexData;
            IndexDataPtr mpIndexData;

            std::list<Vector3> mPositionList;
            std::list<Vector3> mNormalList;
            std::list<Vector3> mTangentList;
            std::list<Color> mColorList;
            std::list<Vector2> mTexCoordList;

            std::list<uint32_t> mIndexList;
    };

    typedef SharedPtr<DynamicGeometry> DynamicGeometryPtr;
}

#endif
